package com.ruoyi.quartz.util;

import org.quartz.CronExpression;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

/**

 * 
 * @author ruoyi
 *
 */
public class SlUtils
{
    /**
     * 计算两个日期之间的年份
     *
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @return int 相差年份
     */
    public static int getYearNumber(Date startDate, Date endDate)
    {
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(startDate);
        int startYear = startCalendar.get(Calendar.YEAR);
        int startMonth = startCalendar.get(Calendar.MONTH);

        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(endDate);
        int endYear = endCalendar.get(Calendar.YEAR);
        int endMonth = endCalendar.get(Calendar.MONTH);

        // 计算相差的完整月份数
        int monthsDiff = (endYear - startYear) * 12 + (endMonth - startMonth);
        return monthsDiff <12 ? 0 : monthsDiff / 12;
    }

}
